package com.financing.wap.service.impl;


import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.financing.wap.dao.IFpVideoDao;
import com.financing.wap.dao.IProductDao;
import com.financing.wap.dto.FpVideoDTO;
import com.financing.wap.dto.ProductAnnualRevenueDTO;
import com.financing.wap.service.IFpFundInfoService;
import com.financing.wap.service.IFpVideoService;
/**
 * fp_video  
 * 路演视频 业务访问层实现类
 * @author lisu
 *
 */
 
@Repository("fpVideoService")
public class FpVideoServiceImpl implements IFpVideoService{
	
	Logger logger = Logger.getLogger(getClass());

	@Autowired
	private IFpVideoDao fpVideoDao;
	@Autowired
	private IProductDao productDao;
	@Autowired
	private IFpFundInfoService fpFundInfoService;
	@Override
	public int insert(FpVideoDTO fpVideo) throws SQLException {
		return fpVideoDao.insert(fpVideo);
	}

	@Override
	public void update(FpVideoDTO fpVideo) throws SQLException {
		fpVideoDao.update(fpVideo);
	}

	@Override
	public void updateForce(FpVideoDTO fpVideo) throws SQLException {
		fpVideoDao.updateForce(fpVideo);
	}

	@Override
	public void delete(Integer id) throws SQLException {
		fpVideoDao.delete(id);
	}
	
	@Override
	public List<FpVideoDTO> queryList(FpVideoDTO fpVideo) throws SQLException {
		List<FpVideoDTO> list = fpVideoDao.queryList(fpVideo);
		
		for (FpVideoDTO bean:list) {
			
			//信托，资管，pevc 获取最高收益信息
			if("02".equals(bean.getProductType()) || "03".equals(bean.getProductType()) || "06".equals(bean.getProductType())){
				
				logger.info("产品id："+bean.getProductId());
				
				ProductAnnualRevenueDTO profitHight = productDao.queryAnnualRevenue(bean.getProductId(),"h");
				profitHight = profitHight == null?new ProductAnnualRevenueDTO():profitHight;
				
				logger.info("收益："+profitHight.getExpectAnnualRevenue());
				
				bean.getVideoProduct().setExpectAnnualRevenue(profitHight.getExpectAnnualRevenue());
			}
		}
		
		
		return list;
	}

	@Override
	public int queryListCount(FpVideoDTO fpVideo) throws SQLException {
		return fpVideoDao.queryListCount(fpVideo);
	}

	@Override
	public FpVideoDTO loadById(Integer id) throws SQLException {
		return fpVideoDao.loadById(id);
	}
 	@Override
	public FpVideoDTO queryListGetFirst(FpVideoDTO fpVideo)
			throws SQLException {
		 List<FpVideoDTO> queryList = queryList(fpVideo);
		 if(queryList==null||queryList.size()==0){
			 return new FpVideoDTO();
		 }
		 return queryList.get(0);
	}

	@Override
	public FpVideoDTO queryVideoInfo(FpVideoDTO fpVideo) throws SQLException {
		return fpVideoDao.queryVideoInfo(fpVideo);
	}
}
